package com.sh1604.duitang.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.bartoszlipinski.recyclerviewheader2.RecyclerViewHeader;
import com.google.gson.Gson;
import com.sh1604.duitang.R;
import com.sh1604.duitang.constant.OKHttpUtils;
import com.sh1604.duitang.constant.UrlString;
import com.sh1604.duitang.mybean.Bean;
import com.sh1604.duitang.mybean.HomeCollectDataBean;
import com.sh1604.duitang.view.TitleView;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class HomeItemCollectActivity extends AppCompatActivity {
    private Bean.DataBean.ObjectListBean bean;
   // private List<HomeCollectDataBean.DataBean> mList;
    private ListView lv;
    private TitleView titleView;
    private List<String> mList;
    private ArrayAdapter<String> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_item_collect);
        lv= (ListView) findViewById(R.id.lv_collect);
//        RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
//        RecyclerViewHeader rv_other = (RecyclerViewHeader) findViewById(R.id.rv_other);
//        rv_other.attachTo(rv);

         mList = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            mList.add("m---->"+i);
        }
            adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,mList);
        lv.setAdapter(adapter);
        getExtra();
        titleView = new TitleView(getApplication());
        lv.addHeaderView(titleView);
    }

    private void getExtra() {
        Intent intent = getIntent();
        bean = (Bean.DataBean.ObjectListBean) intent.getSerializableExtra("bean");
        String target = bean.getTarget();
        String id = target.substring(target.indexOf("id="),target.length());
        String targetId
                = UrlString.URL_HOME_ITEMCOLLECT_BASE+id+UrlString.URL_HOME_ITEMCOLLECT_TAIL;
        Log.i("123",targetId);
        OKHttpUtils.newInstance(this).getAsyncMainData(targetId, new OKHttpUtils.MyCallBack() {
            @Override
            public void onFailure(IOException e) {

            }

            @Override
            public void onResponse(String result) {
                HomeCollectDataBean dataBean = new Gson().fromJson(result, HomeCollectDataBean.class);
               // mList.add(dataBean.getData());
               //
                titleView.setData(dataBean.getData());

            }
        },null);
    }



}
